package com.example.antdback.config;

import com.example.antdback.entity.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ljg
 * 异常统一处理
 */
@Slf4j
@ControllerAdvice
public class MyExceptionHandler {

    
    @ResponseBody
    @ExceptionHandler(value = Exception.class) //异常可以细化，比如业务异常，数据异常等，然后提示不同的信息
    public Result<String> handle(Exception e) {
        log.error("系统出错，原因是:" + e);
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }

}
